/*
 *  IR Sensor class using the Sharp GP2D12 IR range finder
 *
 *  The expectation is that the readSensor routine would be
 *  called continuously and it will inticate true when a reading
 *  was actually made.  Internal timers specify the timing cycle
 *
 */

#ifndef IRSENSOR_H_
#define IRSENSOR_H_

#include <WProgram.h>

#define INVALID_DISTANCE -1
 
class IrSensor
{
public:
  /*  Constructor, initialize our sensor
   *
   */
  IrSensor(const uint8_t pin);
  
  /*  Invoke a sensor reading
   *
   *  param: distance (out) the value in centimeters
   *
   *  returns true if it was a successful read
   *
   */
  bool readSensor(int & distance);
  
  /*  Get the last sensor reading
   *
   *  returns the value in centimeters
   *
   */
  int getLastSensorReading();
  
  /*  Get the time of last sensor read
   *
   *  returns the value in milliseconds
   *
   */
  int getLastSensorReadingTime();
  
  /* Retrieve the initialization Delay
   *  
   */
  int getSensorInitDelay();
   
  /*  Retrieve the time between reads
   * 
   */
  int getSensorReadDelay();
   
  
  
private:

  /* Converts the analog value to centimeters
   *
   */
  int convertValueToDistance( int value );

  uint8_t my_pin;
  
  int last_distance;  
  
  unsigned long last_read_time;
  
};

#endif // #ifndef IRSENSOR_H_
